home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C16 / TStackTest.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  930 b   |  35 lines

  1. //: C16:TStackTest.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Use template list & iterator
  7. #include "TStack.h"
  8. #include "../require.h"
  9. #include <iostream>
  10. #include <fstream>
  11. #include <string>
  12. using namespace std;
  13.  
  14. int main() {
  15.   ifstream file("TStackTest.cpp");
  16.   assure(file, "TStackTest.cpp");
  17.   TStack<string> textlines;
  18.   // Read file and store lines in the list:
  19.   string line;
  20.   while(getline(file, line))
  21.     textlines.push(new string(line));
  22.   int i = 0;
  23.   // Use iterator to print lines from the list:
  24.   TStackIterator<string> it(textlines);
  25.   TStackIterator<string>* it2 = 0;
  26.   while(it) {
  27.     cout << *it.current() << endl;
  28.     it++;
  29.     if(++i == 10) // Remember 10th line
  30.       it2 = new TStackIterator<string>(it);
  31.   }
  32.   cout << *(it2->current()) << endl;
  33.   delete it2;
  34. } ///:~
  35.